package com.hnguigu.health.houduan.lcj.controller_lcj;

import com.google.gson.Gson;
import com.hnguigu.health.houduan.lcj.pojo_lcj.PagVo_lcj;
import com.hnguigu.health.houduan.lcj.pojo_lcj.TDiseaseLibrary_lcj;
import com.hnguigu.health.houduan.lcj.service_lcj.TDiseaseLibraryService_lcj;
import com.hnguigu.health.pojo.TSportsItemLibrary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/tdislib")
public class TDiseaseLibraryController_lcj {
    @Autowired(required = false)
    TDiseaseLibraryService_lcj tdislibser;

    @PostMapping("/getall")
    @ResponseBody
    public PagVo_lcj<TDiseaseLibrary_lcj> getall(@RequestBody Map<String,String> map){
        TDiseaseLibrary_lcj tDiseaseLibrary_lcj = new TDiseaseLibrary_lcj();
        String name = map.get("name");
        String clinicDepartmentId = map.get("clinicDepartmentId");
        if(("请选择科室名").equals(clinicDepartmentId)){
            tDiseaseLibrary_lcj.setClinicDepartmentId("0");
        }else{
            tDiseaseLibrary_lcj.setClinicDepartmentId(clinicDepartmentId);
        }
        tDiseaseLibrary_lcj.setName(name);
        return tdislibser.getpage(Integer.valueOf(map.get("page")),Integer.valueOf(map.get("num")),tDiseaseLibrary_lcj);
    }

    @GetMapping("adddislib")
    @ResponseBody
    public Integer adddislib(String dislib){
        Gson gson = new Gson();
        TDiseaseLibrary_lcj tDiseaseLibrary_lcj = gson.fromJson(dislib, TDiseaseLibrary_lcj.class);
        TDiseaseLibrary_lcj lastbean = tdislibser.Lastbean();
        String code = lastbean.getCode();
        String newTmid="";
        String substring="";
        if(lastbean==null){
            newTmid="JB001";
        }else{
            substring = code.substring(2, code.length());
        }
        if(Integer.parseInt(substring)<10){
            newTmid= "JB00"+(Integer.parseInt(substring)+1);
        }
        if(Integer.parseInt(substring)>=10){
            newTmid= "Jb0"+(Integer.parseInt(substring)+1);
        }
        if(Integer.parseInt(substring)>=100){
            newTmid= "Jb"+(Integer.parseInt(substring)+1);
        }
        tDiseaseLibrary_lcj.setCode(newTmid);
        System.out.println(tDiseaseLibrary_lcj+"添加疾病");
        tdislibser.insertSelective(tDiseaseLibrary_lcj);
        return 1;
    }
    @GetMapping("upddislib")
    @ResponseBody
    public Integer upddislib(String tim,String dislib){
        Gson gson = new Gson();
        TDiseaseLibrary_lcj tDiseaseLibrary_lcj = gson.fromJson(dislib, TDiseaseLibrary_lcj.class);
        tDiseaseLibrary_lcj.setUpdateTime(tim);
        tdislibser.updateByPrimaryKeySelective(tDiseaseLibrary_lcj);
        return 1;
    }
    @GetMapping("delislib")
    @ResponseBody
    public Integer deldislib(String id){
        tdislibser.deleteByPrimaryKey(Integer.valueOf(id));
        return 1;
    }

    @GetMapping("/bycode")
    @ResponseBody
    public Integer bycode(String code){
        TDiseaseLibrary_lcj bycode = tdislibser.getBycode(code);
        if (bycode==null){
            return 1;
        }else{
            return 2;
        }
    }
}
